package {{packageName}}.core.{{entity.module}}.domain;

import java.util.*;
{{#if entity.hasBigDecimal}}
import java.math.BigDecimal;
{{/if}}
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.util.*;
import org.springframework.data.annotation.*;
import cn.ibizlab.util.annotation.*;
import cn.ibizlab.util.enums.*;
import cn.ibizlab.util.domain.IEntity;
import cn.ibizlab.util.domain.EntityBase;
import java.io.Serializable;
import lombok.*;
import lombok.experimental.Accessors;
import io.swagger.annotations.*;
{{#entity.allRelEntities}}
import {{packageName}}.core.{{module}}.domain.{{domainClassName}};
{{/entity.allRelEntities}}

/**
 * {{entity.logicName}}实体类[{{entity.codeName}}]
 *
 * @author generator
 */
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
@JsonIgnoreProperties(value = "handler")
@ApiModel(value = "{{entity.name}}", description = "{{entity.logicName}}")
public class {{entity.domainClassName}} extends EntityBase implements Serializable
{
    {{#each entity.properties}}
    /**
     * {{logicName}}
     */
    {{#if keyDEField}}
    @Id
    {{/if}}
    {{#auditInfoFormat}}
    @Audit
    {{/auditInfoFormat}}
    @DEField({{annotation}})
    {{#if jsonName}}
        {{#if timeType}}
    @JsonFormat(pattern = "{{format}}", locale = "zh", timezone = "GMT+8")
    @JSONField(name = "{{jsonName}}" , format = "{{format}}")
        {{else}}
    @JSONField(name = "{{jsonName}}")
        {{/if}}
    @JsonProperty("{{jsonName}}")
    {{else}}
    @JsonIgnore
    @JSONField(serialize = false)
    {{/if}}
    {{#eq type.java "Long"}}
    @JsonSerialize(using = ToStringSerializer.class)
    {{/eq}}
    @ApiModelProperty(value = "{{columnName}}", notes = "{{logicName}}")
    private {{javaType}} {{camelCase codeName}};

    {{/each}}
   {{#each entity.properties}}
        {{#unless builtinField}}
    /**
    * 设置 [{{logicName}}]
    */
    public {{entity.domainClassName}} set{{pascalCase codeName}}({{javaType}} {{camelCase codeName}}) {
        this.{{camelCase codeName}} = {{camelCase codeName}};
        this.modify("{{jsonName}}", {{camelCase codeName}});
        return this;
    }

        {{/unless}}
        {{#if refType}}
    @JsonProperty("{{lowerCase opt.codeName}}")
    @JSONField(name = "{{lowerCase opt.codeName}}")
    public {{entity.domainClassName}} set{{pascalCase codeName}}(Map<Object,{{refType}}> {{camelCase codeName}}) {
        return this.set{{pascalCase codeName}}({{camelCase codeName}}!=null?{{camelCase codeName}}.values().stream().collect(java.util.stream.Collectors.toList()):null);
    }

    @JsonProperty("{{lowerCase opt.codeName}}")
    @JSONField(name = "{{lowerCase opt.codeName}}")
    public Map<Object,{{refType}}> get{{pascalCase codeName}}() {
        return this.{{camelCase codeName}}!=null?{{camelCase codeName}}.stream().collect(java.util.stream.Collectors.toMap({{refType}}::get{{pascalCase refGroup}}, java.util.function.Function.identity(), (o1, o2) -> o1, LinkedHashMap::new)):null;
    }

        {{/if}}
    {{/each}}

    {{#if entity.keyField.type.number}}
    @Override
    public Serializable getDefaultKey(boolean gen) {
        return com.baomidou.mybatisplus.core.toolkit.IdWorker.getId();
    }

    {{/if}}
    {{#if entity.hasResetField}}
    /**
     * 复制当前对象数据到目标对象(粘贴重置)
     * @param targetEntity 目标数据对象
     * @param includeEmpty  是否包括空值
     * @param <T>
     * @return
     */
    @Override
    public <T> T pasteTo(T targetEntity, boolean includeEmpty) {
        super.pasteTo(targetEntity, includeEmpty);
        if(targetEntity instanceof IEntity) {
            IEntity entity = ((IEntity) targetEntity);
    {{#each entity.fields}}
        {{#if pasteReset}}
            entity.reset("{{lowerCase name}}");
        {{/if}}
    {{/each}}
        }
        return targetEntity;
    }

    {{/if}}
}